package cn.hdustea.shopNavigation.net;

import com.google.gson.GsonBuilder;
import com.hdustea.base.net.HttpConfig;

import cn.hdustea.shopNavigation.config.ConstantUrl;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class RetrofitSearch {
    private Retrofit mRetrofit;

    private RetrofitSearch() {

        mRetrofit = new Retrofit.Builder()
                .baseUrl("http://127.0.0.1:8629")
                .addConverterFactory(GsonConverterFactory.create(new GsonBuilder().setLenient().create()))
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .client(HttpConfig.createOkHttpClient())
                .build();
    }

    private static final class RetrofitSearchHolder {
        private final static RetrofitSearch INSTANCE = new RetrofitSearch();
    }

    private static RetrofitSearch getInstance() {
        return RetrofitSearch.RetrofitSearchHolder.INSTANCE;
    }

    public static <T> T init(Class<T> service) {
        return getInstance().mRetrofit.create(service);
    }

}
